package org.kzwl.book.controller.app;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.kzwl.comm.advice.Consts;
import org.kzwl.comm.pojo.ResponseData;
import org.kzwl.comm.pojo.bo.heritage.HeritageBasicBO;
import org.kzwl.comm.pojo.bo.heritage.QueryLimitBO;
import org.kzwl.comm.pojo.dto.heritage.HeritageBasicDTO;
import org.kzwl.comm.utils.MyUtils;
import org.kzwl.entity.web.CuHeritageCategory;
import org.kzwl.service.web.CuHeritageCategoryService;
import org.kzwl.service.web.CuHeritageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Api("App非遗文化保护")
@RestController
@RequestMapping("/app-cu-heritage")
public class AppCuHeritageController {

    @Autowired
    CuHeritageCategoryService cuHeritageCategoryService;

    @Autowired
    CuHeritageService cuHeritageService;


    @ApiOperation(value = "分类查询")
    @PostMapping("/queryList")
    public ResponseData<List<CuHeritageCategory>> queryList() {
        return cuHeritageCategoryService.queryList();
    }


    @ApiOperation(value = "非遗文化保护基础查询")
    @PostMapping("/queryBasic")
    public ResponseData<List<HeritageBasicDTO>> queryBasic(@RequestBody HeritageBasicBO bo) {
        IPage<HeritageBasicDTO> page = cuHeritageService.queryBasic(bo);
        page.getRecords().forEach(list -> {
            list.setCuHeritageUrl(Consts.MyConsts.DetailsUrl + "heritage/"+list.getCuHeritageId());
            String s = MyUtils.regExHtml(list.getCuHeritageContent());
            list.setCuHeritageContent(s);
        });
        return new ResponseData<>(page.getRecords());
    }

    @ApiOperation(value = "非遗头条和非遗咨询")
    @PostMapping("/queryLimit")
    public ResponseData<List<HeritageBasicDTO>> queryLimit(@RequestBody QueryLimitBO bo) {
        List<HeritageBasicDTO> list = cuHeritageService.queryLimit(bo);
        list.forEach(l -> {
            l.setCuHeritageUrl(Consts.MyConsts.DetailsUrl + "heritage/" + l.getCuHeritageId());
            String s = MyUtils.regExHtml(l.getCuHeritageContent());
            l.setCuHeritageContent(s);
            l.setCuHeritageDate(null);
        });
        return new ResponseData<>(list);
    }

}
